package com.david.equipment.service.impl;

import com.david.common.utils.PageResult;
import com.david.equipment.mapper.DeviceMapper;
import com.david.equipment.pojo.entity.DeviceEntity;
import com.david.equipment.pojo.vo.DeviceVO;
import com.david.equipment.service.DeviceService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeviceServiceImpl implements DeviceService {
    @Autowired
    private DeviceMapper deviceMapper;

    @Override
    public void addDevice(DeviceEntity device) {
        device.setCreateTime(LocalDateTime.now());
        deviceMapper.insertDevice(device);
    }

    @Override
    public PageResult getList(DeviceVO deviceVO) {
        PageHelper.startPage(deviceVO.getPage(), deviceVO.getPageSize());
        List<DeviceEntity> deviceList = deviceMapper.selectList(deviceVO);
        PageResult pageResult = new PageResult();
        pageResult.setTotal(deviceMapper.selectList(deviceVO).size());
        pageResult.setRecords(deviceList);
        return pageResult;

    }
}
